package com.tedu.charging.service.bill.config;

import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.*;

@Configuration
public class RabbitMQInsideMessageConfig {
    public static final String INSIDE_MESSAGE_EXCHANGE = "insideMessageExchange";
    public static final String ALERT_QUEUE = "alertQueue";
    public static final String ALERT_KEY = "alert";

    public static final String RECHARGE_QUEUE = "rechargeQueue";
    public static final String RECHARGE_KEY = "recharge";

    //创建站内信交换机
    @Bean
    public TopicExchange getInsideExchange() {
        //多次调用加了@bean的方法，得到是同一个实体
        TopicExchange topicExchange = new TopicExchange(INSIDE_MESSAGE_EXCHANGE);
        System.out.println(topicExchange);
        return topicExchange;
    }

    //创建告警队列
    @Bean
    public Queue getAlertQueue() {
        return new Queue(ALERT_QUEUE);
    }

    //将告警队列与交换机绑定
    @Bean
    public Binding alertBinding() {
        return BindingBuilder.bind(getAlertQueue()).to(getInsideExchange()).with(ALERT_KEY);
    }

    //创建充值队列
    @Bean
    public Queue getRechargeQueue() {
        return new Queue(RECHARGE_QUEUE);
    }

    //将充值队列与交换机绑定
    @Bean
    public Binding rechargeBinding() {
        return BindingBuilder.bind(getRechargeQueue()).to(getInsideExchange()).with(RECHARGE_KEY);
    }

}
